package com.heima.controller;


import com.heima.pojo.dto.TbPartnerDto;
import com.heima.pojo.vo.PageResponse;
import com.heima.pojo.vo.TbPartnerVo;
import com.heima.service.ITbPartnerService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 合作商表 前端控制器
 * </p>
 *
 * @author AkiRinko
 * @since 2024-06-06
 */
@RestController
@RequestMapping("/api/user-service/partner")
@RequiredArgsConstructor
public class TbPartnerController {

    private final ITbPartnerService tbPartnerService;

    /**
     * 合作商搜索
     *
     * @param pageIndex
     * @param pageSize
     * @param name
     */
    @GetMapping("/search")
    private PageResponse<TbPartnerVo> selectPageList(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                     @RequestParam(value = "name", required = false) String name) {
        return tbPartnerService.selectPageList(pageIndex, pageSize, name);
    }

    /**
     * 新增合作商
     *
     * @param dto
     */
    @PostMapping
    private void insertPartner(@RequestBody TbPartnerDto dto) {
        tbPartnerService.insertPartner(dto);
    }

    /**
     * 获取合作商详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    private TbPartnerVo selectById(@PathVariable Integer id) {
        return tbPartnerService.selectById(id);
    }

    /**
     * 修改合作商
     * @param id
     * @param dto
     */
    @PutMapping("/{id}")
    private void updateById(@PathVariable Integer id,
                            @RequestBody TbPartnerDto dto) {
        tbPartnerService.updatePartnerById(id, dto);
    }

    /**
     * 删除合作商
     * @param id
     */
    @DeleteMapping("/{id}")
    private void deleteById(@PathVariable Integer id) {
        tbPartnerService.deletePartnerById(id);
    }

    /**
     * 合作商数量
     * @return
     */
    @GetMapping("/count")
    private Integer partnerCount(){
        return tbPartnerService.partnerCount();
    }
}
